package com.example.mydemo.threadPool;

import java.util.concurrent.Executors;
import java.util.concurrent.SynchronousQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 直接提交队列
 */
public class SynchronousQueueDemo {

    /**
     * 直接提交队列
     *  没有容量，不存任务
     */
    final static SynchronousQueue<Runnable> synchronousQueue = new SynchronousQueue();

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 2, 5, TimeUnit.SECONDS, synchronousQueue
                , Executors.defaultThreadFactory(), new ThreadPoolExecutor.AbortPolicy());

        for (int i = 0; i < 10; i++) {
            executor.execute(()->{
                System.out.println(Thread.currentThread().getName());
            });
        }

    }



}
